using System;
using System.Collections.Generic;
using System.Text;
using ECommerce.DAL;
using System.Data.SqlClient;
using System.Data;

namespace Entity
{
    [System.ComponentModel.DataObject]
    public class TblEventsExtended : TblEvents
    {
        public static CustomCollection<TblEvents> GetActiveEventsByCount(int howMany)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@howMany", SqlDbType.Int, 0, ParameterDirection.Input, howMany);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EVENTS_GET_ACTIVE_EVENTS_BY_COUNT);
            GenerateCollectionFromReader reader = new GenerateCollectionFromReader(GenerateTblEventsCollectionFromReader);
            CustomCollection<TblEvents> objCollection = ((CustomCollection<TblEvents>)ExecuteReaderCmd(sqlCmd, reader));
            return objCollection;
        }

        public static int GetActiveEventsCount()
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EVENTS_GET_ACTIVE_EVENTS_COUNT);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        public static CustomCollection<TblEvents> GetNonDeletedEventsPaged(string orderBy, int startRow, int pageSize)
        {
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EVENTS_GET_NONDELETED_EVENTS_PAGED);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblEventsCollectionFromReader);
            CustomCollection<TblEvents> objCollection = ((CustomCollection<TblEvents>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        public static int GetNonDeletedEventsCount()
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EVENTS_GET_NONDELETED_EVENTS_COUNT);

            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        public static CustomCollection<TblEvents> GetAllEventsByEventsNamePaged(string eventsName, string orderBy, int startRow, int pageSize)
        {
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@eventsName", SqlDbType.NVarChar, 500, ParameterDirection.Input, eventsName);
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EVENTS_GET_ALL_EVENTS_BY_NAME_PAGED);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblEventsCollectionFromReader);
            CustomCollection<TblEvents> objCollection = ((CustomCollection<TblEvents>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        public static int GetAllEventsByEventsNameCount(string eventsName)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@eventsName", SqlDbType.NVarChar, 500, ParameterDirection.Input, eventsName);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EVENTS_GET_ALL_EVENTS_BY_NAME_COUNT);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        public static CustomCollection<TblEvents> GetNonDeletedEventsByEventsNamePaged(string eventsName, string orderBy, int startRow, int pageSize)
        {
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@eventsName", SqlDbType.NVarChar, 500, ParameterDirection.Input, eventsName);
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EVENTS_GET_NONDELETED_EVENTS_BY_NAME_PAGED);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblEventsCollectionFromReader);
            CustomCollection<TblEvents> objCollection = ((CustomCollection<TblEvents>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        public static int GetNonDeletedEventsByEventsNameCount(string eventsName)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@eventsName", SqlDbType.NVarChar, 500, ParameterDirection.Input, eventsName);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EVENTS_GET_NONDELETED_EVENTS_BY_NAME_COUNT);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        private const string SP_TBL_EVENTS_GET_ACTIVE_EVENTS_BY_COUNT = "sp_TblEvents_Get_Active_Events_By_Count";
        private const string SP_TBL_EVENTS_GET_ACTIVE_EVENTS_COUNT = "sp_TblEvents_Get_Active_Events_Count";
        private const string SP_TBL_EVENTS_GET_NONDELETED_EVENTS_PAGED = "sp_TblEvents_Get_NonDeleted_Events_Paged";
        private const string SP_TBL_EVENTS_GET_NONDELETED_EVENTS_COUNT = "sp_TblEvents_Get_NonDeleted_Events_Count";
        private const string SP_TBL_EVENTS_GET_ALL_EVENTS_BY_NAME_PAGED = "sp_TblEvents_Get_All_Events_By_Name_Paged";
        private const string SP_TBL_EVENTS_GET_ALL_EVENTS_BY_NAME_COUNT = "sp_TblEvents_Get_All_Events_By_Name_Count";
        private const string SP_TBL_EVENTS_GET_NONDELETED_EVENTS_BY_NAME_PAGED = "sp_TblEvents_Get_NonDeleted_Events_By_Name_Paged";
        private const string SP_TBL_EVENTS_GET_NONDELETED_EVENTS_BY_NAME_COUNT = "sp_TblEvents_Get_NonDeleted_Events_By_Name_Count";

    }
}
